import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		enabled : [{ name:'未使用', value:0 },{ name:'已使用', value:1 },{ name:'已删除', value:-1 }],
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'id' },
			{ label: '操作人',		name: 'real_name'},
			{ label: '医院名称',		name: 'hosp_id',		type:'select' },
			{ label: '使用状态',		name: 'enabled', 		type:'select',	data:[{ name:'未使用', value:0 },{ name:'已使用', value:1 }]},
			{ label: '生成时间',		names: ['created_at_start_date','created_at_end_date'], 	type:'date-range', 	loading:true },
		],
	}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院名称
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'bs-hospital/select' }) )
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'barcode/getBarcodeSpecList')
	controls = ()=> []
	
	// 表单
	cols = [
		{ title: '标本条码', 	dataIndex: 'id', 				...$fn.table.spec_code },
		{ title: '操作人', 		dataIndex: 'real_name', 		...$fn.table.name },
		{ title: '医院名称', 	dataIndex: 'hosp_name', 		width:200 },
		{ title: '使用状态', 	dataIndex: 'enabled', 			width:100,	render: text => $fn.getState(this.state.enabled,text) },
		{ title: '生成时间', 	dataIndex: 'created_at',  		...$fn.table.time},
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, {idStr: 'id', type: -1, isInit: window.isInit} ) }
			</>
		)
	}
}

export default Index